<?php
/**
 * @Author: nic-tes
 * @Date:   2014-09-05 16:40:26
 * @Last Modified by:   nic-tes
 * @Last Modified time: 2014-09-05 16:51:48
 */
/**
 * 分类控制器
 */
class CategoryControl extends CommonControl{
	/**
	 * [index 添加顶级分类]
	 * @return [type] [description]
	 */
	public function index(){
		if (IS_POST) {
			$data=array(
				'title'=>trim(adds_html($_POST['title'])),
				'pid'=>0

				);
			$bloon=M('category')->add($data);
			if($bloon)$this->success('添加成功',__ROOT__.'?c=category&m=category');
		}
		
		$this->display();
	}
	/**
	 * [category 分类列表]
	 * @return [type] [description]
	 */
	public function category(){
		$cate=M('category')->all();
		$cate=$this->limitless($cate);
		$this->assign('cate',$cate);
		$this->display();
	}
	/**
	 * [add_cate 添加子级分类]
	 */
	public function add_cate(){
		if (IS_POST) {
			$data=array(

			'title'=>trim(adds_html($_POST['title'])),
			'pid'=>(int)trim(adds_html($_POST['pid']))
				);
			$bloon=M('category')->add($data);
			if($bloon)$this->success('添加成功',__ROOT__.'?c=category&m=category');

			

		}
		$this->display();
	}
	/**
	 * [edit_cate 编辑分类]
	 * @return [type] [description]
	 */
	public function edit_cate(){
		$name=M('category')->where('cid='.(int)$_GET['cid'])->find();
		$this->assign('name',$name);
		if (IS_POST) {
			$data=array('title'=>trim(adds_html($_POST['title'])));
			$bloon=M('category')->where('cid='.(int)$_POST['cid'])->update($data);
			if($bloon)$this->success('修改成功',__ROOT__.'?c=category&m=category');
		}
		$this->display();
	}
	/**
	 * [del_cate 删除分类]
	 * @return [type] [description]
	 */
	public function del_cate(){
		if(!empty($_GET['cid'])){
			$data=M('category')->where('pid='.$_GET['cid'])->find();
			if($data!=null){
				$this->error('请把所有子分类删除');
			}else{
				$bloon=M('category')->where('cid='.$_GET['cid'])->delete();
				if($bloon)$this->success('删除成功',__ROOT__."?c=category&m=category");
			}

		}
	}
}
?>